package model;

public class CalculateNextContractStateStrategy implements CalculateNextStateStrategy{
	
	public SMSObjectState getNextState(SMSObject smsObject, RuleSelector ruleSelector) {
		
		boolean status = ruleSelector.processRuleRequest();
		Rule rule = ruleSelector.getRule();
		//Contract contract;
		//System.out.println("Rule: "+ ruleSelector.getRule().getRuleDescripton());
		SMSObjectState currentState = smsObject.getCurrentState();
		if (status == true) {
			
			if (smsObject instanceof Opportunity && currentState instanceof Approved) {
				return new Imported();
			} else if (currentState instanceof Imported) {
				return new Prepared();
			} else if (currentState instanceof Prepared) {
				Contract c = (Contract)smsObject;
				if(c.getMaxLevel()-1 == c.getCurrentLevel())				
					return new Approved();
				else
					return new Prepared();
			} else if (currentState instanceof Approved) {
				return new Finalized();
			}
		}else{
			if (currentState instanceof Prepared) {
				return new Imported();
			} 
		}
		
		return smsObject.getCurrentState();
		
	}

}
